comparing stored timestamp with NOW()

comparing stored timestamp with NOW()

am 24.02.2009 22:35:06 von Terion Miller

--001485f945a693e2210463b0e42d
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi I need help formatting a sql statement that compares my stored timestamp
$stamp with NOW()
what I'm trying to do is generate a SELECT statement that pulls only records
within 7 days of NOW()
should i use

*SELECT DATEDIFF('stamp','NOW()')=7d; not sure how the difference
part is syntaxed*

Thanks
Terion

Happy Freecycling
Free the List !!
www.freecycle.org
Over Moderation of Freecycle List Prevents Post Timeliness.
------------------------------------------------
Twitter?
http://twitter.com/terionmiller
------------------------------------------------
Facebook:
title="Terion Miller's Facebook profile" target=_TOP> alt="Terion Miller's Facebook profile">
Vince Lombardi - "Winning is habit. Unfortunately, so is losing."

--001485f945a693e2210463b0e42d--

Re: comparing stored timestamp with NOW()

am 25.02.2009 00:00:59 von andresmontanez

If your timestamps is an UNIX Timestamp,
and your DB is MySQL, this should do the trick

$days =3D 7;
$sql =3D 'SELECT (UNIX_TIMESTAMP() - ' . $timeStamp . ') <=3D (3600*24*' .
$days . ');';

3600*24 is one day in seconds, so multiply it by the days limit (7 days).

Example Query:
mysql> SELECT (UNIX_TIMESTAMP() - 1235861716) <=3D (3600*24*7) AS valid FRO=
M dual;
+-------+
| valid |
+-------+
| 1 |
+-------+

Enjoy.

--=20
Atte, Andr=E9s G. Monta=F1ez
Zend Certified Engineer
Montevideo - Uruguay

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: comparing stored timestamp with NOW()

am 25.02.2009 00:11:50 von Nicholas Mercier

$days =3D 7;
$now =3D date(Y-m-d);
$timestamp =3D /*your defined stamp */;
$query =3D "SELECT * from TABLE WHERE DATEDIFF('$timestamp', '$now')<=3D7";

I think that is the query you want? Unless I'm misreading the manual -
which is entirely possible.

Conversely you can just use DATEDIFF('$timestamp', DATE())<=3D7 as well.
The only thing you need to make sre is that your $timestamp is in
YYYY-MM-DD format.

On Tue, Feb 24, 2009 at 4:35 PM, Terion Miller wr=
ote:
> Hi I need help formatting a sql statement that compares my stored timesta=
mp
> $stamp with NOW()
> what I'm trying to do is generate a SELECT statement that pulls only reco=
rds
> within 7 days of NOW()
> should i use
>
> =A0*SELECT DATEDIFF('stamp','NOW()')=3D7d; not sure how the difference
> part is syntaxed*
>
> Thanks
> Terion
>
> Happy Freecycling
> Free the List !!
> www.freecycle.org
> Over Moderation of Freecycle List Prevents Post Timeliness.
> ------------------------------------------------
> Twitter?
> http://twitter.com/terionmiller
> ------------------------------------------------
> Facebook:
> > title=3D"Terion Miller's Facebook profile" target=3D_TOP> > http://badge.facebook.com/badge/1542024891.237.919247960.png " border=3D0
> alt=3D"Terion Miller's Facebook profile">

> Vince Lombardi =A0- "Winning is habit. Unfortunately, so is losing."
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php